#!/bin/sh
#Target directory where will be createt the next target
#rootfs
TARGET_ROOTFS_DIR="target-rootfs"

#Directories used to mount some microSD partitions 
echo "Create mount directories"
mkdir $TARGET_ROOTFS_DIR/media/mmc_p1
mkdir $TARGET_ROOTFS_DIR/media/data

#Set the target board hostname
filename=$TARGET_ROOTFS_DIR/etc/hostname
echo Creating $filename
echo aria > $filename

#Set the defalt name server
filename=$TARGET_ROOTFS_DIR/etc/resolv.conf
echo Creating $filename
echo nameserver 8.8.8.8 > $filename
echo nameserver 8.8.4.4 >> $filename

#Set the default network interfaces
filename=$TARGET_ROOTFS_DIR/etc/network/interfaces
echo Creating $filename
#Set the loopback
echo auto lo >> $filename
echo iface lo inet loopback >> $filename
#Set the wlan0
echo auto wlan0
echo allow-hotplug wlan0 >> $filename
echo iface wlan0 inet dhcp >> $filename
echo wpa-ssid louis_ap >> $filename
echo wpa-psk vvcxhk3h >> $filename


#Set a terminal to the debug port
filename=$TARGET_ROOTFS_DIR/etc/inittab
echo Updating $filename
echo T0:2345:respawn:/sbin/getty -L ttyS0 115200 vt100 >> $filename

#Set how to mount the microSD partitions
filename=$TARGET_ROOTFS_DIR/etc/fstab
echo Creating $filename
echo /dev/mmcblk0p1 /media/mmc_p1 vfat noatime 0 1 > $filename
echo /dev/mmcblk0p2 / ext4 noatime 0 1 >> $filename
echo /dev/mmcblk0p3 /media/data ext4 noatime 0 1 >> $filename
echo proc /proc proc defaults 0 0 >> $filename

#Add the standard Debian repositories. In this way it is possible
#to install packages not included in the Emdebian/Grip repositories
filename=$TARGET_ROOTFS_DIR/etc/apt/sources.list
echo Creating $filename
echo deb http://ftp.fr.debian.org/debian wheezy main  > $filename                     
echo deb http://security.debian.org/ wheezy/updates main  >> $filename

#Add the standard Debian non-free repositories useful to load
#closed source firmware (i.e. WiFi dongle firmware)
echo deb http://http.debian.net/debian/ wheezy main contrib non-free >> $filename

#Add firmware for Wi-Fi for edimax key
mkdir $TARGET_ROOTFS_DIR/lib/firmware/rtlwifi
cd $TARGET_ROOTFS_DIR/lib/firmware/rtlwifi
wget http://chromium.arnoldthebat.co.uk/files/fw/lib/firmware/rtlwifi/rtl8192cufw.bin

#add resolve address for ftp.fr.debian.org
filename=$TARGET_ROOTFS_DIR/etc/hosts
echo Updating $filename
echo 212.27.32.66 >> $filename

